package demo.practice.binary_search;

public class P240 {
    //240. 搜索二维矩阵 II
    public boolean searchMatrix(int[][] matrix, int target) {

        if (matrix == null || matrix.length == 0 || matrix[0].length == 0)
            return false;

        int i = 0;
        int j = matrix.length - 1;

        while (i < matrix[0].length && j >= 0) {

            if (matrix[j][i] == target) {
                return true;
            } else if (matrix[j][i] > target) {
                j--;
            } else {
                i++;
            }
        }

        return false;
    }
}
